// -------------------------------------------------
// BlinKit - BlinKit Library
// -------------------------------------------------
//   File Name: qjs_form_element.cpp
// Description: Bindings for HTMLFormElement
//      Author: Ziming Li
//     Created: 2022-10-25
// -------------------------------------------------
// Copyright (C) 2022 MingYang Software Technology.
// -------------------------------------------------

#include "./qjs_bindings.h"

#include "blinkit/blink/renderer/bindings/core/qjs/qjs.h"
#include "blinkit/blink/renderer/bindings/core/qjs/qjs_c_function_list_entries.h"
#include "blinkit/blink/renderer/bindings/core/script_controller.h"
#include "blinkit/blink/renderer/core/html/HTMLFormElement.h"

/**
 * https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement
 */

namespace BlinKit {
namespace qjs {

static JSValue Submit(JSContext *ctx, JSValueConst thisVal, int, JSValueConst *)
{
    ScriptWrappable::Cast<HTMLFormElement>(thisVal)->submitFromJavaScript();
    return JS_UNDEFINED;
}

JSValue CreateFormElementPrototype(JSContext *ctx, JSValue elementPrototype)
{
    static const JSCFunctionListEntry Funcs[] = {
        CFunctionEntry("submit", 0, Submit)
    };

    JSValue ret = JS_NewObjectProto(ctx, elementPrototype);
    JS_SetPropertyFunctionList(ctx, ret, Funcs, std::size(Funcs));
    return ret;
}

} // namespace qjs
} // namespace BlinKit
